def union(a, b):
    temp = a.copy()
    for x in b:
        if x not in temp:
            temp.append(x)

    return temp


def difference(a, b):
    temp = a.copy()
    for x in b:
        if x in temp:
            temp.remove(x)
        else:
            temp.append(x)

    return temp


def intersection(a, b):
    tempA = a.copy()
    tempB = b.copy()
    temp = []
    for x in tempA:
        if x in tempB:
            temp.append(x)

    return temp


if __name__ == '__main__':
    a = [[1], [2], [3, 4], [5], [6], [7, 8, 9]]
    b = [[1], [2, 3], [4], [5, 6], [7, 8, 9]]

    t1 = [['aaa'], ['bbb'], ['ccc'], ['ddd']]
    t2 = t1[0]
    print(difference(t1, [t2]))
    print(union(a, b))
    print(difference(a, b))
    print(intersection(a, b))
